package com.jumei.flume.sink.kudu;

import com.jumei.bi.datasource.DoveProxyDruidDataSource;
import com.jumei.bi.kudu.ReloadableKuduClient;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;

import javax.sql.DataSource;

/**
 * @author yic
 * @Title: KuduConfiguration
 * @Package com.jumei.bi.gluttony.configuration
 * @Description: (工程的kudu配置类，配置比较基本的kudu信息)
 * @date 2017/10/30 15:53
 */
public class KuduConfiguration {

    /**
     * 聚美idc机房kudu集群
     * 
     * @return
     */
    public DataSource dataSource4kudu() {
        DoveProxyDruidDataSource dataSource = new DoveProxyDruidDataSource();
        dataSource.setDoveKey("bi_refactor.datasource.jdbc");
        dataSource.setSourceId("impala_bi_kudu_cube_srd");
        dataSource.setPoolPreparedStatements(true);
        dataSource.setMaxActive(30);
        return dataSource;
    }

    public JdbcTemplate jdbcTemplate4Kudu() {
        return new JdbcTemplate(dataSource4kudu());
    }

    public NamedParameterJdbcTemplate namedParameterJdbcTemplate4Kudu() {
        return new NamedParameterJdbcTemplate(dataSource4kudu());
    }
    

    public ReloadableKuduClient kuduClient() {
        ReloadableKuduClient kuduClient = new ReloadableKuduClient();
        kuduClient.setDoveKey("Res.Kudu.kudu1.5");
        try {
			kuduClient.afterPropertiesSet();
		} catch (Exception e) {
			
			
			return null;
		}//非spring托管，强制调用此方法
        return kuduClient;
    }

    /**
     * 腾讯云机房kudu集群
     * @return
     */    
    public DataSource dataSource4kudu4tx() {
        DoveProxyDruidDataSource dataSource = new DoveProxyDruidDataSource();
        dataSource.setDoveKey("bi_refactor.datasource.jdbc");
        dataSource.setSourceId("impala_bi_kudu_cube_srd_tx");
        dataSource.setPoolPreparedStatements(true);
        dataSource.setMaxActive(30);
        return dataSource;
    }

    public JdbcTemplate jdbcTemplate4Kudu4tx() {
        return new JdbcTemplate(dataSource4kudu4tx());
    }

    public NamedParameterJdbcTemplate namedParameterJdbcTemplate4Kudu4tx() {
        return new NamedParameterJdbcTemplate(dataSource4kudu4tx());
    }
    

    public ReloadableKuduClient kuduClient4tx() {
        ReloadableKuduClient kuduClient = new ReloadableKuduClient();
        kuduClient.setDoveKey("Res.Kudu.kudu.tx");
        try {
			kuduClient.afterPropertiesSet();
		} catch (Exception e) {
			
			
			return null;
		}//非spring托管，强制调用此方法
        return kuduClient;
    }

    public ReloadableKuduClient kuduClient4Shuabao() {
        ReloadableKuduClient kuduClient = new ReloadableKuduClient();
        kuduClient.setDoveKey("Res.kudu.kudu.shuabao");
        try {
            kuduClient.afterPropertiesSet();
        } catch (Exception e) {
            return null;
        }//非spring托管，强制调用此方法
        return kuduClient;
    }

//
//    private static KuduConfiguration instance;
//    
//    public static KuduConfiguration getInstance() {
//    	if(null == instance) {
//    		instance = new KuduConfiguration();
//    	}
//    	
//    	return instance;
//    }
}
